import {
  amountFormat
} from "@/assets/js/util";
export default {
  data() {
    return {};
  },

  methods: {
    // 获取移动终端的语言
    getLang() {
      let lang = localStorage.getItem("lang") || "";
      const langAll = ["EN", "ZH", "ES", "VI"];
      let momentLang = localStorage.getItem("moment_lang") || "vi";
      if (localStorage.getItem("lang")) {} else {
        // 默认使用越南语，不再检测浏览器语言
        lang = "VI";
        momentLang = "vi";
      }
      if (!langAll.includes(lang)) {
        lang = "VI";
        momentLang = "vi"
      }
      this.$moment.locale(momentLang);
      this.$store.commit("SET_LANG", lang);
      this.$i18n.locale = lang;
      localStorage.setItem("lang", lang);
      localStorage.setItem("moment_lang", momentLang);
    },

    //金额格式化
    formatMoney(value) {
      return amountFormat(value);
    },


    // 获取时间段
    getDuration(val) {
      const duration = this.$moment.duration(parseInt(val / 1000), 'seconds')
      let days = Math.floor(duration.asDays()) > 0 ? this.padZero(Math.floor(duration.asDays())) + this.$t('Date_Day') : ''
      let hours = this.padZero(duration.hours()) + this.$t('Date_Hrs')
      let minutes = this.padZero(duration.minutes()) + this.$t('Date_Mins')
      let seconds = this.padZero(duration.seconds()) + this.$t('Date_Secs')
      return `${days}${hours}${minutes}${seconds}`
    },
    padZero(num) {
      if (num < 10) {
        return '0' + num
      } else {
        return num
      }
    },
  }
};
